<#include "/include/macros.ftl">
<@header></@header>
<div class="clearfix"></div>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <ol class="breadcrumb">
            <li><a href="/">首页</a></li>
            <li class="active">字典管理</li>
        </ol>
        <div class="x_panel">
            <div class="x_content">
                <div class="<#--table-responsive-->">
                    <div class="btn-group hidden-xs" id="toolbar">
                        <@shiro.hasPermission name="dict:add">
                        <button id="btn_add" type="button" class="btn btn-default" title="新增字典">
                            <i class="fa fa-plus"></i> 新增字典
                        </button>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name="dict:batchDelete">
                            <button id="btn_delete" type="button" class="btn btn-default" title="删除选中">
                                <i class="fa fa-trash-o"></i> 批量删除
                            </button>
                        </@shiro.hasPermission>
                    </div>
                    <table id="tablelist">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="toolbar1" class="btn-group" style="display:none;">
<@shiro.hasPermission name="dict:2add">
	<button id="btn_add2" type="button" class="btn btn-default">
      <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
    </button>
</@shiro.hasPermission>
<@shiro.hasPermission name="dict:2batchDelete">
	<button id="btn_delete2" type="button" class="btn btn-default" onclick="delMemberVideo();">
	<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
	</button>
</@shiro.hasPermission>
</div>

<!--弹框-->
<div class="modal fade bs-example-modal-sm" id="selectRole" tabindex="-1" role="dialog" aria-labelledby="selectRoleLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="selectRoleLabel">分配角色</h4>
            </div>
            <div class="modal-body">
                <form id="boxRoleForm">
                    <div class="zTreeDemoBackground left">
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"> 关闭</i></button>
            </div>
        </div>
    </div>
</div>
<!--/弹框-->

 <#include "/dict/dictTypeDetail.ftl" />
 
<!--添加用户弹框-->
<div class="modal fade" id="addOrUpdateModal" tabindex="-1" role="dialog" aria-labelledby="addroleLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="addroleLabel">添加字典</h4>
            </div>
            <div class="modal-body">
                <form id="addOrUpdateForm" class="form-horizontal form-label-left" novalidate>
                    <input type="hidden" name="id">
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictType">字典大类: <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictType" id="dictType" required="required" placeholder="请输入字典大类"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictName">字典名称: <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" id="dictName" name="dictName" required="required" placeholder="请输入字典名称"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictDesc">字典描述:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictDesc" id="dictDesc" placeholder="请输入字典描述"/>
                        </div>
                    </div>
                 <!--    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeId">字典值:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeId" id="dictTypeId"  placeholder="请输入字典值"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeName">字典值名称:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeName" id="dictTypeName" placeholder="请输入字典值名称"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeComment">DICT_TYPE_COMMENT:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeComment" id="dictTypeComment" placeholder="请输入"/>
                        </div>
                    </div>
                     <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeRemark">DICT_TYPE_REMARK:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeRemark" id="dictTypeRemark" placeholder="请输入"/>
                        </div>
                    </div> -->
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"> 关闭</i></button>
                <button type="button" class="btn btn-success addOrUpdateBtn"><i class="fa fa-save"> 保存</i></button>
            </div>
        </div>
    </div>
</div>
<!--/添加用户弹框-->



<div class="modal fade" id="addOrUpdateModal2" tabindex="-1" role="dialog" aria-labelledby="addroleLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="addroleLabel">添加字典</h4>
            </div>
            <div class="modal-body">
                <form id="addOrUpdateForm2" class="form-horizontal form-label-left" novalidate>
                    <input type="hidden" name="id">
                     <input type="hidden" name="dictType">
                      <input type="hidden" name="dictName">
                       <input type="hidden" name="dictDesc">
                    <!-- <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictType">字典大类: <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictType" id="dictType" required="required" placeholder="请输入字典大类"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictName">字典名称: <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" id="dictName" name="dictName" required="required" placeholder="请输入字典名称"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictDesc">字典描述:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictDesc" id="dictDesc" placeholder="请输入字典描述"/>
                        </div>
                    </div> -->
                     <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeId">字典值:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeId" id="dictTypeId"  placeholder="请输入字典值"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeName">字典值名称:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" class="form-control col-md-7 col-xs-12" name="dictTypeName" id="dictTypeName" placeholder="请输入字典值名称"/>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeComment">注释:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea type="text" class="form-control col-md-7 col-xs-12" name="dictTypeComment" id="dictTypeComment" placeholder="请输入"></textarea>
                        </div>
                    </div>
                     <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dictTypeRemark">备注:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea type="text" class="form-control col-md-7 col-xs-12" name="dictTypeRemark" id="dictTypeRemark" placeholder="请输入"></textarea>
                        </div>
                    </div> 
                     <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderNum">排序:</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="number" class="form-control col-md-7 col-xs-12" name="orderNum" id="orderNum" placeholder="请输入"/>
                        </div>
                    </div> 
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"> 关闭</i></button>
                <button type="button" class="btn btn-success addOrUpdateBtn2"><i class="fa fa-save"> 保存</i></button>
            </div>
        </div>
    </div>
</div>


<@footer>
    <script>
        /**
         * 操作按钮
         * @param code
         * @param row
         * @param index
         * @returns {string}
         */
        function operateFormatter(code, row, index) {
            var currentUserId = '${user.id}';
            var trDictId = row.dictType;
            var operateBtn = [
                '<@shiro.hasPermission name="dict:edit"><a class="btn btn-xs btn-primary btn-update" data-id="' + trDictId + '"><i class="fa fa-edit"></i>编辑</a></@shiro.hasPermission>',
            ];
                operateBtn.push('<@shiro.hasPermission name="dict:delete"><a class="btn btn-xs btn-danger btn-remove" data-id="' + trDictId + '"><i class="fa fa-trash-o"></i>删除</a></@shiro.hasPermission>');
                operateBtn.push('<@shiro.hasPermission name="dict:detail"><a class="btn btn-xs btn-info btn-dicttype" data-id="' + trDictId + '"><i class="fa fa-circle-thin"></i>细类</a></@shiro.hasPermission>')
            return operateBtn.join('');
        }
         
         function operateVersion(code, row, index) {
          	var dictId = row.id;
              var operateBtn = [
                  '<@shiro.hasPermission name="dict:2edit"><a class="btn btn-xs btn-primary btn-update2" data-id="' + dictId + '"><i class="fa fa-envelope-o"></i>编辑</a></@shiro.hasPermission>',
                  '<@shiro.hasPermission name="dict:2delete"><a class="btn btn-xs btn-success btn-remove2" data-id="' + dictId + '"><i class="fa  fa-arrows-alt"></i>删除</a></@shiro.hasPermission>',
              ];
              return operateBtn.join('');
          }
         
         
         
         $("#btn_delete").click(function () {
        	 var selectedJson = $("#tablelist").bootstrapTable('getAllSelections');
        	    var ids = [];
        	    $.each(selectedJson, function (i) {
        	        ids.push(selectedJson[i].dictType);
        	    });
             if (!ids || ids == '[]' || ids.length == 0) {
                 $.alert.error("请至少选择一条记录");
                 return;
             }
             $.alert.confirm("确定删除该字典信息？", function () {
                 $.ajax({
                     type: "post",
                     url: "/dict/remove",
                     traditional: true,
                     data: {'ids': ids},
                     success: function (json) {
                         $.alert.ajaxSuccess(json);
                         $.tableUtil.refresh();
                     },
                     error: $.alert.ajaxError
                 });
             }, function () {

             }, 5000);
         });
         
         $("#btn_delete2").click(function () {
        	 var selectedJson = $("#versionlist").bootstrapTable('getAllSelections');
        	    var ids = [];
        	    $.each(selectedJson, function (i) {
        	        ids.push(selectedJson[i].id);
        	    });
             if (!ids || ids == '[]' || ids.length == 0) {
                 $.alert.error("请至少选择一条记录");
                 return;
             }
             $.alert.confirm("确定删除该字典信息？", function () {
                 $.ajax({
                     type: "post",
                     url: "/dict/remove2",
                     traditional: true,
                     data: {'ids': ids},
                     success: function (json) {
                         $.alert.ajaxSuccess(json);
                         $("#versionlist").bootstrapTable('refresh', {url:'/dict/dictDetail/'+$("#addOrUpdateModal2 input[name='dictType']").val()});
                     },
                     error: $.alert.ajaxError
                 });
             }, function () {

             }, 5000);
         });

         $("#btn_add2").click(function () {
             $("#addOrUpdateModal2").modal('show');
             $("#addOrUpdateModal2").find(".modal-dialog .modal-content .modal-header h4.modal-title").html("添加字典值");

             $("#addOrUpdateModal2 input[name='id']").val('');
             $("#addOrUpdateModal2 input[name='dictTypeId']").val('');
             $("#addOrUpdateModal2 input[name='dictTypeName']").val('');
             $("#addOrUpdateModal2 textarea[name='dictTypeComment']").val('');
             $("#addOrUpdateModal2 textarea[name='dictTypeRemark']").val('');
             $("#addOrUpdateModal2 input[name='orderNum']").val('');
             $(".addOrUpdateBtn2").unbind('click');
             
             $(".addOrUpdateBtn2").click(function () {
             	var t = $('#addOrUpdateForm2').serializeArray();
                 if (validator.checkAll($("#addOrUpdateForm2"))) {
                     $.ajax({
                         type: "post",
                         url: "/dict/add2",
                         data: $("#addOrUpdateForm2").serialize(),
                         success: function (json) {
                             $.alert.ajaxSuccess(json);
                             $("#addOrUpdateModal2").modal('hide');
                             $("#versionlist").bootstrapTable('refresh', {url:'/dict/dictDetail/'+$("#addOrUpdateModal2 input[name='dictType']").val()});
                         },
                         error: $.alert.ajaxError
                     });
                 }
             })
             
             $(".addOrUpdateBtn2").show();
         });
         
         $('#versionlist').on('click', '.btn-remove2', function () {
        	 var $this = $(this);
             var dictId = $this.attr("data-id");
             $.alert.confirm("确定删除该字典信息？", function () {
                 $.ajax({
                     type: "post",
                     url: "/dict/remove2",
                     traditional: true,
                     data: {'ids': dictId},
                     success: function (json) {
                         $.alert.ajaxSuccess(json);
                         $("#versionlist").bootstrapTable('refresh', {url:'/dict/dictDetail/'+$("#addOrUpdateModal2 input[name='dictType']").val()});
                     },
                     error: $.alert.ajaxError
                 });
             }, function () {

             }, 5000);
             
        	 
         });

         /* 修改 */
         $('#versionlist').on('click', '.btn-update2', function () {
             var $this = $(this);
             var dictId = $this.attr("data-id");
             $("#addOrUpdateModal2").modal('show');
             $("#addOrUpdateModal2").find(".modal-dialog .modal-content .modal-header h4.modal-title").html("修改字典");
             
             $.ajax({
                 type: "post",
                 url: "/dict/getid/"+dictId,
                 success: function (json) {
                     var info = json.data;
                     
                     $("#addOrUpdateModal2 form input,#addOrUpdateModal2 form select,#addOrUpdateModal2 form textarea").each(function () {
                         var $this = $(this);
                         var thisName = $this.attr("name");
                         var thisValue = info[thisName];
                         $this.val(thisValue);
                     });
                     
        			 $(".addOrUpdateBtn2").unbind('click');
                     
                     $(".addOrUpdateBtn2").click(function () {
                     	var t = $('#addOrUpdateForm2').serializeArray();
                         if (validator.checkAll($("#addOrUpdateForm2"))) {
                             $.ajax({
                                 type: "post",
                                 url: "/dict/edit2",
                                 data: $("#addOrUpdateForm2").serialize(),
                                 success: function (json) {
                                     $.alert.ajaxSuccess(json);
                                     $("#addOrUpdateModal2").modal('hide');
                                     $("#versionlist").bootstrapTable('refresh', {url:'/dict/dictDetail/'+$("#addOrUpdateModal2 input[name='dictType']").val()});
                                 },
                                 error: $.alert.ajaxError
                             });
                         }
                     })
                     

                     $(".addOrUpdateBtn2").show();
                     
                     
                 },
                 error: $.alert.ajaxError
             });
             
             
           
             
         });
         
         
        $(function () {
            var options = {
                url: "/dict/list",
                getInfoUrl: "/dict/get/{id}",
                updateUrl: "/dict/edit",
                removeUrl: "/dict/remove",
                createUrl: "/dict/add",
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'dictType',
                        title: '字典大类',
                        editable: false,
                    }, {
                        field: 'dictName',
                        title: '字典名称',
                        editable: false
                    }, {
                        field: 'dictDesc',
                        title: '字典描述',
                        editable: false
                    }, {
                        field: 'operate',
                        title: '操作',
                        events: {
                            'click .btn-dicttype' : function(e, value, row, index) {
                            	$("#addOrUpdateModal2 input[name='dictType']").val(row.dictType);
                            	$("#addOrUpdateModal2 input[name='dictName']").val(row.dictName);
                            	$("#addOrUpdateModal2 input[name='dictDesc']").val(row.dictDesc);
                            	dictType(e, value, row, index);
                            }
                        },
                        formatter: operateFormatter //自定义方法，添加操作按钮
                    }
                ],
                modalName: "字典"
            };
            //1.初始化Table
            $.tableUtil.init(options);
            //2.初始化Button的点击事件
            $.buttonUtil.init(options);

            
            
            /* 查看评估内容 */
           // $('#tablelist').on('click', '.btn-dicttype', function (a,b,c,d) {
        	   function dictType(e, value, row, index){
                console.log("查看数据字典明细");
                var $this = $(this);
                var dictType = row.dictType;//$this.attr("data-id");
                $('#toolbar1').css({"display":"block"});
                $('#versionlist').children().remove(); 
                
                function queryParams(params) {      
                	var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的         // limit: params.limit,   //页面大小         
                			offset: params.offset,  //页码          
                			pageSize:this.pageSize,          
                			pageNumber:this.pageNumber,         
                			"dict.dictType":dictType,
                			length: 6      
                			};      
                	return temp;  
                };


                $('#versionlist').bootstrapTable('destroy').bootstrapTable({
                            url: '/dict/dictDetail/'+dictType,
                            method: 'post',                      //请求方式（*）
                            striped: true,                      //是否显示行间隔色
                            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                            contentType: "application/x-www-form-urlencoded", // 发送到服务器的数据编码类型, application/x-www-form-urlencoded为了实现post方式提交
                            sortable: false,                     //是否启用排序
                            sortOrder: "asc",                   //排序方式
                            sortStable: true,                   // 设置为 true 将获得稳定的排序
                            queryParams: queryParams,//传递参数（*）
                            queryParamsType: '',
                            pagination: true,                   //是否显示分页（*）
                            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                            pageNumber: 1,                       //初始化加载第一页，默认第一页
                            pageSize: 10,                       //每页的记录行数（*）
                            pageList: [10,20, 40, 50, 100, 150],        //可供选择的每页的行数（*）
                            search: true,                       //是否启用搜索框 根据sidePagination选择从前后台搜索
                            strictSearch: true,                 //设置为 true启用 全匹配搜索，否则为模糊搜索
                            searchOnEnterKey: true,            // 设置为 true时，按回车触发搜索方法，否则自动触发搜索方法
                            minimumCountColumns: 1,             //最少允许的列数
                            showColumns: true,                  //是否显示 内容列下拉框
                            showRefresh: true,                  //是否显示刷新按钮
                            toolbar : "#toolbar1",
                            // detailView: true,                   //是否显示父子表
                            // showExport: true,                   //是否显示导出
                            // exportDataType: "basic",              //basic', 'all', 'selected'.
                            // clickToSelect: true,                //是否启用点击选中行
                            // singleSelect: true,
                            //height: 400,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                            columns: [
                            	{
                                    checkbox: true
                                }, {
                                    field: 'id',
                                    title: '编号',
                                    visible :false,
                                    editable: false,
                                },  {
                                    field: 'dictType',
                                    title: '字典类型',
                                    visible :true,
                                    editable: false,
                                    formatter: function (value,row,index) {
                                        return value;
                                    }
                                }, {
                                    field: 'dictName',
                                    title: '类型名称',
                                    editable: false,
                                    formatter: function (value) {
                                        return "<a href='#'>"+value+"</a>";
                                    }
                                }, {
                                    field: 'dictTypeId',
                                    title: '类型值',
                                    visible :true,
                                    editable: false
                                }, {
                                    field: 'dictTypeName',
                                    title: '类型值名称',
                                    visible :true,
                                    editable: false,
                                }, {
                                    field: 'dictTypeComment',
                                    title: '注释',
                                    visible :true,
                                    editable: false
                                }, {
                                    field: 'dictTypeRemark',
                                    title: '备注',
                                    visible :true,
                                    editable: false,
                                }, {
                                    field: 'orderNum',
                                    title: '排序',
                                    visible :true,
                                    editable: false,
                                }, {
                                    field: 'operate1',
                                    title: '操作',
                                    visible :true,
                                    //events : operateEvents,
                                    formatter: operateVersion //自定义方法，添加操作按钮
                                }]
                        });
                        
                        $('#selectVersion').modal('show');
                      $("#versionlist").bootstrapTable('refresh', {url:'/dict/dictDetail/'+dictType});
        	   }
        	   //});
            
        });
    </script>
    
    <script src="/assets/js/yyl.dict.js"></script>
</@footer>